home *** CD-ROM | disk | FTP | other *** search
- /* Sleep Now was written by Geoffrey Keating, 31/3/1996. It is public domain. */
-
- /* written for Universal Headers 2.1 */
- #define SystemSevenOrLater 1
- #define OLDROUTINENAMES 0
- #define OLDROUTINELOCATIONS 0
- #include <ControlStrip.h>
- #include <Icons.h>
- #include <Gestalt.h>
-
- /* resource ID of the small icon we draw */
- #define ourIconID 257
-
- /* stuff to control the screen saver */
- #define gestaltScreenSaverControl 'SAVC'
- enum
- {
- eSaverWakeUp = 0,
- eSaverSleep = 1,
- eSaverOn = 2,
- eSaverOff = 3
- };
- typedef short SaverCommand;
- typedef pascal OSErr (*SaverControlProcPtr) (SaverCommand command);
-
- /* the main (and only) routine for the sdev */
- pascal long
- main(long message, Handle iconSuite, Rect *statusRect, GrafPtr statusPort)
- {
- SaverControlProcPtr scp;
-
- switch (message)
- {
- case sdevInitModule:
- /* on init, we grab and save our icon */
- if (SBGetDetachIconSuite(&iconSuite, ourIconID, kSelectorAllSmallData) == noErr)
- return (long)iconSuite;
- else
- break;
- case sdevCloseModule:
- /* on close, we dispose the icon we got on startup */
- if (iconSuite != NULL)
- DisposeIconSuite(iconSuite, true);
- break;
- case sdevFeatures:
- return 1<<sdevWantMouseClicks;
- case sdevGetDisplayWidth:
- return 16; /* width of our icon */
- case sdevDrawStatus:
- PlotIconSuite(statusRect, kAlignAbsoluteCenter, kTransformNone, iconSuite);
- break;
- case sdevMouseClick:
- /* call the screen saver and tell it to sleep */
- if (Gestalt(gestaltScreenSaverControl, (long *)&scp) == noErr &&
- scp != NULL)
- (*scp)(eSaverSleep);
- else
- /* if there is no screen saver, we're redundant, and should close. */
- return 1<<sdevCloseNow;
- break;
- default:
- break;
- }
- return 0;
- }
-